<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=emulateIE7" />
    <title>Coverage for app\main\views.py: 27%</title>
    <link rel="icon" sizes="32x32" href="favicon_32.png">
    <link rel="stylesheet" href="style.css" type="text/css">
    <script type="text/javascript" src="jquery.min.js"></script>
    <script type="text/javascript" src="jquery.hotkeys.js"></script>
    <script type="text/javascript" src="jquery.isonscreen.js"></script>
    <script type="text/javascript" src="coverage_html.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(coverage.pyfile_ready);
    </script>
</head>
<body class="pyfile">
<div id="header">
    <div class="content">
        <h1>Coverage for <b>app\main\views.py</b> :
            <span class="pc_cov">27%</span>
        </h1>
        <img id="keyboard_icon" src="keybd_closed.png" alt="Show keyboard shortcuts" />
        <h2 class="stats">
            197 statements &nbsp;
            <button type="button" class="run shortkey_r button_toggle_run" title="Toggle lines run">63 run</button>
            <button type="button" class="mis show_mis shortkey_m button_toggle_mis" title="Toggle lines missing">134 missing</button>
            <button type="button" class="exc show_exc shortkey_x button_toggle_exc" title="Toggle lines excluded">0 excluded</button>
            <button type="button" class="par run show_par shortkey_p button_toggle_par" title="Toggle lines partially run">0 partial</button>
        </h2>
    </div>
</div>
<div class="help_panel">
    <img id="panel_icon" src="keybd_open.png" alt="Hide keyboard shortcuts" />
    <p class="legend">Hot-keys on this page</p>
    <div>
    <p class="keyhelp">
        <span class="key">r</span>
        <span class="key">m</span>
        <span class="key">x</span>
        <span class="key">p</span> &nbsp; toggle line displays
    </p>
    <p class="keyhelp">
        <span class="key">j</span>
        <span class="key">k</span> &nbsp; next/prev highlighted chunk
    </p>
    <p class="keyhelp">
        <span class="key">0</span> &nbsp; (zero) top of page
    </p>
    <p class="keyhelp">
        <span class="key">1</span> &nbsp; (one) first highlighted chunk
    </p>
    </div>
</div>
<div id="source">
    <p id="t1" class="pln"><span class="n"><a href="#t1">1</a></span><span class="t"><span class="com">#!/usr/bin/env python</span>&nbsp;</span><span class="r"></span></p>
    <p id="t2" class="pln"><span class="n"><a href="#t2">2</a></span><span class="t"><span class="com"># -*- coding: utf-8 -*-</span>&nbsp;</span><span class="r"></span></p>
    <p id="t3" class="pln"><span class="n"><a href="#t3">3</a></span><span class="t"><span class="com"># @Time    : 2021/3/15 11:33</span>&nbsp;</span><span class="r"></span></p>
    <p id="t4" class="pln"><span class="n"><a href="#t4">4</a></span><span class="t"><span class="com"># @Author  : Wang Yuhang</span>&nbsp;</span><span class="r"></span></p>
    <p id="t5" class="pln"><span class="n"><a href="#t5">5</a></span><span class="t"><span class="com"># @File    : views.py</span>&nbsp;</span><span class="r"></span></p>
    <p id="t6" class="pln"><span class="n"><a href="#t6">6</a></span><span class="t"><span class="com"># @Func    : &#36335;&#30001;&#22788;&#29702;&#31243;&#24207;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t7" class="pln"><span class="n"><a href="#t7">7</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t8" class="run"><span class="n"><a href="#t8">8</a></span><span class="t"><span class="key">from</span> <span class="nam">datetime</span> <span class="key">import</span> <span class="nam">datetime</span>&nbsp;</span><span class="r"></span></p>
    <p id="t9" class="run"><span class="n"><a href="#t9">9</a></span><span class="t"><span class="key">from</span> <span class="nam">flask</span> <span class="key">import</span> <span class="nam">render_template</span><span class="op">,</span> <span class="nam">session</span><span class="op">,</span> <span class="nam">redirect</span><span class="op">,</span> <span class="nam">url_for</span><span class="op">,</span> <span class="nam">flash</span><span class="op">,</span> <span class="nam">current_app</span><span class="op">,</span> <span class="nam">abort</span><span class="op">,</span> <span class="nam">request</span><span class="op">,</span> <span class="nam">make_response</span>&nbsp;</span><span class="r"></span></p>
    <p id="t10" class="run"><span class="n"><a href="#t10">10</a></span><span class="t"><span class="key">from</span> <span class="nam">flask_login</span> <span class="key">import</span> <span class="nam">login_required</span><span class="op">,</span> <span class="nam">current_user</span>&nbsp;</span><span class="r"></span></p>
    <p id="t11" class="pln"><span class="n"><a href="#t11">11</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t12" class="run"><span class="n"><a href="#t12">12</a></span><span class="t"><span class="key">from</span> <span class="op">.</span> <span class="key">import</span> <span class="nam">main</span>&nbsp;</span><span class="r"></span></p>
    <p id="t13" class="run"><span class="n"><a href="#t13">13</a></span><span class="t"><span class="key">from</span> <span class="op">.</span><span class="nam">forms</span> <span class="key">import</span> <span class="nam">NameForm</span><span class="op">,</span> <span class="nam">EditProfileForm</span><span class="op">,</span> <span class="nam">EditProfileAdminForm</span><span class="op">,</span> <span class="nam">PostForm</span><span class="op">,</span> <span class="nam">CommentForm</span>&nbsp;</span><span class="r"></span></p>
    <p id="t14" class="run"><span class="n"><a href="#t14">14</a></span><span class="t"><span class="key">from</span> <span class="op">.</span><span class="op">.</span> <span class="key">import</span> <span class="nam">db</span>&nbsp;</span><span class="r"></span></p>
    <p id="t15" class="run"><span class="n"><a href="#t15">15</a></span><span class="t"><span class="key">from</span> <span class="op">.</span><span class="op">.</span><span class="nam">models</span> <span class="key">import</span> <span class="nam">User</span><span class="op">,</span> <span class="nam">Permission</span><span class="op">,</span> <span class="nam">Role</span><span class="op">,</span> <span class="nam">Post</span><span class="op">,</span> <span class="nam">Comment</span>&nbsp;</span><span class="r"></span></p>
    <p id="t16" class="run"><span class="n"><a href="#t16">16</a></span><span class="t"><span class="key">from</span> <span class="op">.</span><span class="op">.</span><span class="nam">email</span> <span class="key">import</span> <span class="nam">send_email</span>&nbsp;</span><span class="r"></span></p>
    <p id="t17" class="run"><span class="n"><a href="#t17">17</a></span><span class="t"><span class="key">from</span> <span class="op">.</span><span class="op">.</span><span class="nam">decorators</span> <span class="key">import</span> <span class="nam">admin_required</span><span class="op">,</span> <span class="nam">permission_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t18" class="pln"><span class="n"><a href="#t18">18</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t19" class="pln"><span class="n"><a href="#t19">19</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t20" class="run"><span class="n"><a href="#t20">20</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/moderate/enable/&lt;int:id>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t21" class="run"><span class="n"><a href="#t21">21</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t22" class="run"><span class="n"><a href="#t22">22</a></span><span class="t"><span class="op">@</span><span class="nam">permission_required</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">MODERATE_COMMENTS</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t23" class="run"><span class="n"><a href="#t23">23</a></span><span class="t"><span class="key">def</span> <span class="nam">moderate_enable</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t24" class="mis show_mis"><span class="n"><a href="#t24">24</a></span><span class="t">    <span class="nam">comment</span> <span class="op">=</span> <span class="nam">Comment</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">get_or_404</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t25" class="mis show_mis"><span class="n"><a href="#t25">25</a></span><span class="t">    <span class="nam">comment</span><span class="op">.</span><span class="nam">disabled</span> <span class="op">=</span> <span class="key">False</span>&nbsp;</span><span class="r"></span></p>
    <p id="t26" class="mis show_mis"><span class="n"><a href="#t26">26</a></span><span class="t">    <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">comment</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t27" class="mis show_mis"><span class="n"><a href="#t27">27</a></span><span class="t">    <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.moderate'</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t28" class="pln"><span class="n"><a href="#t28">28</a></span><span class="t">                            <span class="nam">page</span><span class="op">=</span><span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t29" class="pln"><span class="n"><a href="#t29">29</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t30" class="pln"><span class="n"><a href="#t30">30</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t31" class="run"><span class="n"><a href="#t31">31</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/moderate/disable/&lt;int:id>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t32" class="run"><span class="n"><a href="#t32">32</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t33" class="run"><span class="n"><a href="#t33">33</a></span><span class="t"><span class="op">@</span><span class="nam">permission_required</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">MODERATE_COMMENTS</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t34" class="run"><span class="n"><a href="#t34">34</a></span><span class="t"><span class="key">def</span> <span class="nam">moderate_disable</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t35" class="mis show_mis"><span class="n"><a href="#t35">35</a></span><span class="t">    <span class="nam">comment</span> <span class="op">=</span> <span class="nam">Comment</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">get_or_404</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t36" class="mis show_mis"><span class="n"><a href="#t36">36</a></span><span class="t">    <span class="nam">comment</span><span class="op">.</span><span class="nam">disabled</span> <span class="op">=</span> <span class="key">True</span>&nbsp;</span><span class="r"></span></p>
    <p id="t37" class="mis show_mis"><span class="n"><a href="#t37">37</a></span><span class="t">    <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">comment</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t38" class="mis show_mis"><span class="n"><a href="#t38">38</a></span><span class="t">    <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.moderate'</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t39" class="pln"><span class="n"><a href="#t39">39</a></span><span class="t">                            <span class="nam">page</span><span class="op">=</span><span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t40" class="pln"><span class="n"><a href="#t40">40</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t41" class="pln"><span class="n"><a href="#t41">41</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t42" class="run"><span class="n"><a href="#t42">42</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/moderate'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t43" class="run"><span class="n"><a href="#t43">43</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t44" class="run"><span class="n"><a href="#t44">44</a></span><span class="t"><span class="op">@</span><span class="nam">permission_required</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">MODERATE_COMMENTS</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t45" class="run"><span class="n"><a href="#t45">45</a></span><span class="t"><span class="key">def</span> <span class="nam">moderate</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t46" class="mis show_mis"><span class="n"><a href="#t46">46</a></span><span class="t">    <span class="nam">page</span> <span class="op">=</span> <span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t47" class="mis show_mis"><span class="n"><a href="#t47">47</a></span><span class="t">    <span class="nam">pagination</span> <span class="op">=</span> <span class="nam">Comment</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">order_by</span><span class="op">(</span><span class="nam">Comment</span><span class="op">.</span><span class="nam">timestamp</span><span class="op">.</span><span class="nam">desc</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><span class="op">.</span><span class="nam">paginate</span><span class="op">(</span>&nbsp;</span><span class="r"></span></p>
    <p id="t48" class="pln"><span class="n"><a href="#t48">48</a></span><span class="t">        <span class="nam">page</span><span class="op">,</span> <span class="nam">per_page</span><span class="op">=</span><span class="nam">current_app</span><span class="op">.</span><span class="nam">config</span><span class="op">[</span><span class="str">'FLASKY_COMMENTS_PER_PAGE'</span><span class="op">]</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t49" class="pln"><span class="n"><a href="#t49">49</a></span><span class="t">        <span class="nam">error_out</span><span class="op">=</span><span class="key">False</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t50" class="mis show_mis"><span class="n"><a href="#t50">50</a></span><span class="t">    <span class="nam">comments</span> <span class="op">=</span> <span class="nam">pagination</span><span class="op">.</span><span class="nam">items</span>&nbsp;</span><span class="r"></span></p>
    <p id="t51" class="mis show_mis"><span class="n"><a href="#t51">51</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'moderate.html'</span><span class="op">,</span> <span class="nam">comments</span><span class="op">=</span><span class="nam">comments</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t52" class="pln"><span class="n"><a href="#t52">52</a></span><span class="t">                           <span class="nam">pagination</span><span class="op">=</span><span class="nam">pagination</span><span class="op">,</span> <span class="nam">page</span><span class="op">=</span><span class="nam">page</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t53" class="pln"><span class="n"><a href="#t53">53</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t54" class="pln"><span class="n"><a href="#t54">54</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t55" class="run"><span class="n"><a href="#t55">55</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/all'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t56" class="run"><span class="n"><a href="#t56">56</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t57" class="run"><span class="n"><a href="#t57">57</a></span><span class="t"><span class="key">def</span> <span class="nam">show_all</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t58" class="mis show_mis"><span class="n"><a href="#t58">58</a></span><span class="t">    <span class="nam">resp</span> <span class="op">=</span> <span class="nam">make_response</span><span class="op">(</span><span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>          <span class="com"># &#21019;&#24314;&#21709;&#24212;&#23545;&#35937;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t59" class="mis show_mis"><span class="n"><a href="#t59">59</a></span><span class="t">    <span class="nam">resp</span><span class="op">.</span><span class="nam">set_cookie</span><span class="op">(</span><span class="str">'show_followed'</span><span class="op">,</span> <span class="str">''</span><span class="op">,</span> <span class="nam">max_age</span><span class="op">=</span><span class="num">30</span><span class="op">*</span><span class="num">24</span><span class="op">*</span><span class="num">60</span><span class="op">*</span><span class="num">60</span><span class="op">)</span>  <span class="com"># 30&#22825;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t60" class="mis show_mis"><span class="n"><a href="#t60">60</a></span><span class="t">    <span class="key">return</span> <span class="nam">resp</span>&nbsp;</span><span class="r"></span></p>
    <p id="t61" class="pln"><span class="n"><a href="#t61">61</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t62" class="pln"><span class="n"><a href="#t62">62</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t63" class="run"><span class="n"><a href="#t63">63</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/followed'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t64" class="run"><span class="n"><a href="#t64">64</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t65" class="run"><span class="n"><a href="#t65">65</a></span><span class="t"><span class="key">def</span> <span class="nam">show_followed</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t66" class="mis show_mis"><span class="n"><a href="#t66">66</a></span><span class="t">    <span class="nam">resp</span> <span class="op">=</span> <span class="nam">make_response</span><span class="op">(</span><span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t67" class="mis show_mis"><span class="n"><a href="#t67">67</a></span><span class="t">    <span class="nam">resp</span><span class="op">.</span><span class="nam">set_cookie</span><span class="op">(</span><span class="str">'show_followed'</span><span class="op">,</span> <span class="str">'1'</span><span class="op">,</span> <span class="nam">max_age</span><span class="op">=</span><span class="num">30</span><span class="op">*</span><span class="num">24</span><span class="op">*</span><span class="num">60</span><span class="op">*</span><span class="num">60</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t68" class="mis show_mis"><span class="n"><a href="#t68">68</a></span><span class="t">    <span class="key">return</span> <span class="nam">resp</span>&nbsp;</span><span class="r"></span></p>
    <p id="t69" class="pln"><span class="n"><a href="#t69">69</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t70" class="pln"><span class="n"><a href="#t70">70</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t71" class="run"><span class="n"><a href="#t71">71</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/followed_by/&lt;username>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t72" class="run"><span class="n"><a href="#t72">72</a></span><span class="t"><span class="key">def</span> <span class="nam">followed_by</span><span class="op">(</span><span class="nam">username</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t73" class="pln"><span class="n"><a href="#t73">73</a></span><span class="t">    <span class="str">"""</span>&nbsp;</span><span class="r"></span></p>
    <p id="t74" class="pln"><span class="n"><a href="#t74">74</a></span><span class="t"><span class="str">    &#20851;&#27880;&#30340;&#20154;&#21015;&#34920;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t75" class="pln"><span class="n"><a href="#t75">75</a></span><span class="t"><span class="str">    :param username:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t76" class="pln"><span class="n"><a href="#t76">76</a></span><span class="t"><span class="str">    :return:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t77" class="pln"><span class="n"><a href="#t77">77</a></span><span class="t"><span class="str">    """</span>&nbsp;</span><span class="r"></span></p>
    <p id="t78" class="mis show_mis"><span class="n"><a href="#t78">78</a></span><span class="t">    <span class="nam">user</span> <span class="op">=</span> <span class="nam">User</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">filter_by</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">.</span><span class="nam">first</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t79" class="mis show_mis"><span class="n"><a href="#t79">79</a></span><span class="t">    <span class="key">if</span> <span class="nam">user</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t80" class="mis show_mis"><span class="n"><a href="#t80">80</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#26080;&#25928;&#30340;&#29992;&#25143;!"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t81" class="mis show_mis"><span class="n"><a href="#t81">81</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t82" class="mis show_mis"><span class="n"><a href="#t82">82</a></span><span class="t">    <span class="nam">page</span> <span class="op">=</span> <span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t83" class="mis show_mis"><span class="n"><a href="#t83">83</a></span><span class="t">    <span class="nam">pagination</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">followed</span><span class="op">.</span><span class="nam">paginate</span><span class="op">(</span>&nbsp;</span><span class="r"></span></p>
    <p id="t84" class="pln"><span class="n"><a href="#t84">84</a></span><span class="t">        <span class="nam">page</span><span class="op">,</span> <span class="nam">per_page</span><span class="op">=</span><span class="nam">current_app</span><span class="op">.</span><span class="nam">config</span><span class="op">[</span><span class="str">'FLASKY_POSTS_PER_PAGE'</span><span class="op">]</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t85" class="pln"><span class="n"><a href="#t85">85</a></span><span class="t">        <span class="nam">error_out</span><span class="op">=</span><span class="key">False</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t86" class="mis show_mis"><span class="n"><a href="#t86">86</a></span><span class="t">    <span class="nam">follows</span> <span class="op">=</span> <span class="op">[</span><span class="op">{</span><span class="str">'user'</span><span class="op">:</span> <span class="nam">item</span><span class="op">.</span><span class="nam">followed</span><span class="op">,</span> <span class="str">'timestamp'</span><span class="op">:</span> <span class="nam">item</span><span class="op">.</span><span class="nam">timestamp</span><span class="op">}</span> <span class="key">for</span> <span class="nam">item</span> <span class="key">in</span> <span class="nam">pagination</span><span class="op">.</span><span class="nam">items</span><span class="op">]</span>&nbsp;</span><span class="r"></span></p>
    <p id="t87" class="mis show_mis"><span class="n"><a href="#t87">87</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'followers.html'</span><span class="op">,</span> <span class="nam">user</span><span class="op">=</span><span class="nam">user</span><span class="op">,</span> <span class="nam">title</span><span class="op">=</span><span class="str">"&#20851;&#27880;"</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t88" class="pln"><span class="n"><a href="#t88">88</a></span><span class="t">                           <span class="nam">endpoint</span><span class="op">=</span><span class="str">'.followed_by'</span><span class="op">,</span> <span class="nam">pagination</span><span class="op">=</span><span class="nam">pagination</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t89" class="pln"><span class="n"><a href="#t89">89</a></span><span class="t">                           <span class="nam">follows</span><span class="op">=</span><span class="nam">follows</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t90" class="pln"><span class="n"><a href="#t90">90</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t91" class="pln"><span class="n"><a href="#t91">91</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t92" class="run"><span class="n"><a href="#t92">92</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/followers/&lt;username>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t93" class="run"><span class="n"><a href="#t93">93</a></span><span class="t"><span class="key">def</span> <span class="nam">followers</span><span class="op">(</span><span class="nam">username</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t94" class="pln"><span class="n"><a href="#t94">94</a></span><span class="t">    <span class="str">"""</span>&nbsp;</span><span class="r"></span></p>
    <p id="t95" class="pln"><span class="n"><a href="#t95">95</a></span><span class="t"><span class="str">    &#31881;&#19997;&#21015;&#34920;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t96" class="pln"><span class="n"><a href="#t96">96</a></span><span class="t"><span class="str">    :param username:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t97" class="pln"><span class="n"><a href="#t97">97</a></span><span class="t"><span class="str">    :return:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t98" class="pln"><span class="n"><a href="#t98">98</a></span><span class="t"><span class="str">    """</span>&nbsp;</span><span class="r"></span></p>
    <p id="t99" class="mis show_mis"><span class="n"><a href="#t99">99</a></span><span class="t">    <span class="nam">user</span> <span class="op">=</span> <span class="nam">User</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">filter_by</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">.</span><span class="nam">first</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t100" class="mis show_mis"><span class="n"><a href="#t100">100</a></span><span class="t">    <span class="key">if</span> <span class="nam">user</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t101" class="mis show_mis"><span class="n"><a href="#t101">101</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#26080;&#25928;&#30340;&#29992;&#25143;!"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t102" class="mis show_mis"><span class="n"><a href="#t102">102</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t103" class="mis show_mis"><span class="n"><a href="#t103">103</a></span><span class="t">    <span class="nam">page</span> <span class="op">=</span> <span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t104" class="mis show_mis"><span class="n"><a href="#t104">104</a></span><span class="t">    <span class="nam">pagination</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">followers</span><span class="op">.</span><span class="nam">paginate</span><span class="op">(</span>&nbsp;</span><span class="r"></span></p>
    <p id="t105" class="pln"><span class="n"><a href="#t105">105</a></span><span class="t">        <span class="nam">page</span><span class="op">,</span> <span class="nam">per_page</span><span class="op">=</span><span class="nam">current_app</span><span class="op">.</span><span class="nam">config</span><span class="op">[</span><span class="str">'FLASKY_POSTS_PER_PAGE'</span><span class="op">]</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t106" class="pln"><span class="n"><a href="#t106">106</a></span><span class="t">        <span class="nam">error_out</span><span class="op">=</span><span class="key">False</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t107" class="mis show_mis"><span class="n"><a href="#t107">107</a></span><span class="t">    <span class="nam">follows</span> <span class="op">=</span> <span class="op">[</span><span class="op">{</span><span class="str">'user'</span><span class="op">:</span> <span class="nam">item</span><span class="op">.</span><span class="nam">follower</span><span class="op">,</span> <span class="str">'timestamp'</span><span class="op">:</span> <span class="nam">item</span><span class="op">.</span><span class="nam">timestamp</span><span class="op">}</span> <span class="key">for</span> <span class="nam">item</span> <span class="key">in</span> <span class="nam">pagination</span><span class="op">.</span><span class="nam">items</span><span class="op">]</span>&nbsp;</span><span class="r"></span></p>
    <p id="t108" class="mis show_mis"><span class="n"><a href="#t108">108</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'followers.html'</span><span class="op">,</span> <span class="nam">user</span><span class="op">=</span><span class="nam">user</span><span class="op">,</span> <span class="nam">title</span><span class="op">=</span><span class="str">"&#31881;&#19997;"</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t109" class="pln"><span class="n"><a href="#t109">109</a></span><span class="t">                           <span class="nam">endpoint</span><span class="op">=</span><span class="str">'.followers'</span><span class="op">,</span> <span class="nam">pagination</span><span class="op">=</span><span class="nam">pagination</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t110" class="pln"><span class="n"><a href="#t110">110</a></span><span class="t">                           <span class="nam">follows</span><span class="op">=</span><span class="nam">follows</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t111" class="pln"><span class="n"><a href="#t111">111</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t112" class="pln"><span class="n"><a href="#t112">112</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t113" class="run"><span class="n"><a href="#t113">113</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/unfollow/&lt;username>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t114" class="run"><span class="n"><a href="#t114">114</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t115" class="run"><span class="n"><a href="#t115">115</a></span><span class="t"><span class="op">@</span><span class="nam">permission_required</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">FOLLOW</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t116" class="run"><span class="n"><a href="#t116">116</a></span><span class="t"><span class="key">def</span> <span class="nam">unfollow</span><span class="op">(</span><span class="nam">username</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t117" class="pln"><span class="n"><a href="#t117">117</a></span><span class="t">    <span class="str">"""</span>&nbsp;</span><span class="r"></span></p>
    <p id="t118" class="pln"><span class="n"><a href="#t118">118</a></span><span class="t"><span class="str">    &#21462;&#20851;&#25805;&#20316;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t119" class="pln"><span class="n"><a href="#t119">119</a></span><span class="t"><span class="str">    :param username:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t120" class="pln"><span class="n"><a href="#t120">120</a></span><span class="t"><span class="str">    :return:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t121" class="pln"><span class="n"><a href="#t121">121</a></span><span class="t"><span class="str">    """</span>&nbsp;</span><span class="r"></span></p>
    <p id="t122" class="mis show_mis"><span class="n"><a href="#t122">122</a></span><span class="t">    <span class="nam">user</span> <span class="op">=</span> <span class="nam">User</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">filter_by</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">.</span><span class="nam">first</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t123" class="mis show_mis"><span class="n"><a href="#t123">123</a></span><span class="t">    <span class="key">if</span> <span class="nam">user</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t124" class="mis show_mis"><span class="n"><a href="#t124">124</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#26080;&#25928;&#30340;&#29992;&#25143;!"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t125" class="mis show_mis"><span class="n"><a href="#t125">125</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t126" class="mis show_mis"><span class="n"><a href="#t126">126</a></span><span class="t">    <span class="key">if</span> <span class="key">not</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">is_following</span><span class="op">(</span><span class="nam">user</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t127" class="mis show_mis"><span class="n"><a href="#t127">127</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#20320;&#27809;&#26377;&#20851;&#27880;&#27492;&#29992;&#25143;&#65281;"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t128" class="mis show_mis"><span class="n"><a href="#t128">128</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.user'</span><span class="op">,</span> <span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t129" class="mis show_mis"><span class="n"><a href="#t129">129</a></span><span class="t">    <span class="nam">current_user</span><span class="op">.</span><span class="nam">unfollow</span><span class="op">(</span><span class="nam">user</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t130" class="mis show_mis"><span class="n"><a href="#t130">130</a></span><span class="t">    <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">commit</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t131" class="mis show_mis"><span class="n"><a href="#t131">131</a></span><span class="t">    <span class="nam">flash</span><span class="op">(</span><span class="str">'&#20320;&#21462;&#28040;&#20851;&#27880;&#20102; {username} !'</span><span class="op">.</span><span class="nam">format</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t132" class="mis show_mis"><span class="n"><a href="#t132">132</a></span><span class="t">    <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.user'</span><span class="op">,</span> <span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t133" class="pln"><span class="n"><a href="#t133">133</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t134" class="pln"><span class="n"><a href="#t134">134</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t135" class="run"><span class="n"><a href="#t135">135</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/follow/&lt;username>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t136" class="run"><span class="n"><a href="#t136">136</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t137" class="run"><span class="n"><a href="#t137">137</a></span><span class="t"><span class="op">@</span><span class="nam">permission_required</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">FOLLOW</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t138" class="run"><span class="n"><a href="#t138">138</a></span><span class="t"><span class="key">def</span> <span class="nam">follow</span><span class="op">(</span><span class="nam">username</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t139" class="pln"><span class="n"><a href="#t139">139</a></span><span class="t">    <span class="str">"""</span>&nbsp;</span><span class="r"></span></p>
    <p id="t140" class="pln"><span class="n"><a href="#t140">140</a></span><span class="t"><span class="str">    &#20851;&#27880;&#25805;&#20316;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t141" class="pln"><span class="n"><a href="#t141">141</a></span><span class="t"><span class="str">    :param username:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t142" class="pln"><span class="n"><a href="#t142">142</a></span><span class="t"><span class="str">    :return:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t143" class="pln"><span class="n"><a href="#t143">143</a></span><span class="t"><span class="str">    """</span>&nbsp;</span><span class="r"></span></p>
    <p id="t144" class="mis show_mis"><span class="n"><a href="#t144">144</a></span><span class="t">    <span class="nam">user</span> <span class="op">=</span> <span class="nam">User</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">filter_by</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">.</span><span class="nam">first</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t145" class="mis show_mis"><span class="n"><a href="#t145">145</a></span><span class="t">    <span class="key">if</span> <span class="nam">user</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t146" class="mis show_mis"><span class="n"><a href="#t146">146</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#26080;&#25928;&#30340;&#29992;&#25143;!"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t147" class="mis show_mis"><span class="n"><a href="#t147">147</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t148" class="mis show_mis"><span class="n"><a href="#t148">148</a></span><span class="t">    <span class="key">if</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">is_following</span><span class="op">(</span><span class="nam">user</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t149" class="mis show_mis"><span class="n"><a href="#t149">149</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#20320;&#24050;&#20851;&#27880;&#27492;&#29992;&#25143;&#65281;"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t150" class="mis show_mis"><span class="n"><a href="#t150">150</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.user'</span><span class="op">,</span> <span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t151" class="mis show_mis"><span class="n"><a href="#t151">151</a></span><span class="t">    <span class="nam">current_user</span><span class="op">.</span><span class="nam">follow</span><span class="op">(</span><span class="nam">user</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t152" class="mis show_mis"><span class="n"><a href="#t152">152</a></span><span class="t">    <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">commit</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t153" class="mis show_mis"><span class="n"><a href="#t153">153</a></span><span class="t">    <span class="nam">flash</span><span class="op">(</span><span class="str">'&#20320;&#20851;&#27880;&#20102; {username} !'</span><span class="op">.</span><span class="nam">format</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t154" class="mis show_mis"><span class="n"><a href="#t154">154</a></span><span class="t">    <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.user'</span><span class="op">,</span> <span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t155" class="pln"><span class="n"><a href="#t155">155</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t156" class="pln"><span class="n"><a href="#t156">156</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t157" class="run"><span class="n"><a href="#t157">157</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/edit/&lt;int:id>'</span><span class="op">,</span> <span class="nam">methods</span><span class="op">=</span><span class="op">[</span><span class="str">'GET'</span><span class="op">,</span> <span class="str">'POST'</span><span class="op">]</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t158" class="run"><span class="n"><a href="#t158">158</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t159" class="run"><span class="n"><a href="#t159">159</a></span><span class="t"><span class="key">def</span> <span class="nam">edit</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t160" class="mis show_mis"><span class="n"><a href="#t160">160</a></span><span class="t">    <span class="nam">post</span> <span class="op">=</span> <span class="nam">Post</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">get_or_404</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t161" class="mis show_mis"><span class="n"><a href="#t161">161</a></span><span class="t">    <span class="key">if</span> <span class="nam">current_user</span> <span class="op">!=</span> <span class="nam">post</span><span class="op">.</span><span class="nam">author</span> <span class="key">and</span> <span class="key">not</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">can</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">ADMINISTER</span><span class="op">)</span><span class="op">:</span>  <span class="com"># &#24403;&#21069;&#29992;&#25143;&#21644;&#31649;&#29702;&#21592;&#21487;&#20197;&#32534;&#36753;&#25991;&#31456;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t162" class="mis show_mis"><span class="n"><a href="#t162">162</a></span><span class="t">        <span class="nam">abort</span><span class="op">(</span><span class="num">403</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t163" class="mis show_mis"><span class="n"><a href="#t163">163</a></span><span class="t">    <span class="nam">form</span> <span class="op">=</span> <span class="nam">PostForm</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t164" class="mis show_mis"><span class="n"><a href="#t164">164</a></span><span class="t">    <span class="key">if</span> <span class="nam">form</span><span class="op">.</span><span class="nam">validate_on_submit</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t165" class="mis show_mis"><span class="n"><a href="#t165">165</a></span><span class="t">        <span class="nam">post</span><span class="op">.</span><span class="nam">body</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">body</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t166" class="mis show_mis"><span class="n"><a href="#t166">166</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">post</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t167" class="mis show_mis"><span class="n"><a href="#t167">167</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">commit</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t168" class="mis show_mis"><span class="n"><a href="#t168">168</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">'&#25991;&#31456;&#24050;&#32463;&#26356;&#26032;&#65281;'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t169" class="mis show_mis"><span class="n"><a href="#t169">169</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">body</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">post</span><span class="op">.</span><span class="nam">body</span>&nbsp;</span><span class="r"></span></p>
    <p id="t170" class="mis show_mis"><span class="n"><a href="#t170">170</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'edit_post.html'</span><span class="op">,</span> <span class="nam">form</span><span class="op">=</span><span class="nam">form</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t171" class="pln"><span class="n"><a href="#t171">171</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t172" class="pln"><span class="n"><a href="#t172">172</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t173" class="run"><span class="n"><a href="#t173">173</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/post/&lt;int:id>'</span><span class="op">,</span> <span class="nam">methods</span><span class="op">=</span><span class="op">[</span><span class="str">'GET'</span><span class="op">,</span> <span class="str">'POST'</span><span class="op">]</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t174" class="run"><span class="n"><a href="#t174">174</a></span><span class="t"><span class="key">def</span> <span class="nam">post</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t175" class="mis show_mis"><span class="n"><a href="#t175">175</a></span><span class="t">    <span class="nam">post</span> <span class="op">=</span> <span class="nam">Post</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">get_or_404</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t176" class="mis show_mis"><span class="n"><a href="#t176">176</a></span><span class="t">    <span class="nam">form</span> <span class="op">=</span> <span class="nam">CommentForm</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t177" class="mis show_mis"><span class="n"><a href="#t177">177</a></span><span class="t">    <span class="key">if</span> <span class="nam">form</span><span class="op">.</span><span class="nam">validate_on_submit</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t178" class="mis show_mis"><span class="n"><a href="#t178">178</a></span><span class="t">        <span class="nam">comment</span> <span class="op">=</span> <span class="nam">Comment</span><span class="op">(</span><span class="nam">body</span><span class="op">=</span><span class="nam">form</span><span class="op">.</span><span class="nam">body</span><span class="op">.</span><span class="nam">data</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t179" class="pln"><span class="n"><a href="#t179">179</a></span><span class="t">                          <span class="nam">post</span><span class="op">=</span><span class="nam">post</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t180" class="pln"><span class="n"><a href="#t180">180</a></span><span class="t">                          <span class="nam">author</span><span class="op">=</span><span class="nam">current_user</span><span class="op">.</span><span class="nam">_get_current_object</span><span class="op">(</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t181" class="mis show_mis"><span class="n"><a href="#t181">181</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">comment</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t182" class="mis show_mis"><span class="n"><a href="#t182">182</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">commit</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t183" class="mis show_mis"><span class="n"><a href="#t183">183</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">'&#20320;&#30340;&#35780;&#35770;&#24050;&#25552;&#20132;&#65281;'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t184" class="mis show_mis"><span class="n"><a href="#t184">184</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.post'</span><span class="op">,</span> <span class="nam">id</span><span class="op">=</span><span class="nam">post</span><span class="op">.</span><span class="nam">id</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t185" class="mis show_mis"><span class="n"><a href="#t185">185</a></span><span class="t">    <span class="nam">page</span> <span class="op">=</span> <span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t186" class="mis show_mis"><span class="n"><a href="#t186">186</a></span><span class="t">    <span class="nam">pagination</span> <span class="op">=</span> <span class="nam">post</span><span class="op">.</span><span class="nam">comments</span><span class="op">.</span><span class="nam">order_by</span><span class="op">(</span><span class="nam">Comment</span><span class="op">.</span><span class="nam">timestamp</span><span class="op">.</span><span class="nam">desc</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><span class="op">.</span><span class="nam">paginate</span><span class="op">(</span>&nbsp;</span><span class="r"></span></p>
    <p id="t187" class="pln"><span class="n"><a href="#t187">187</a></span><span class="t">        <span class="nam">page</span><span class="op">,</span> <span class="nam">per_page</span><span class="op">=</span><span class="nam">current_app</span><span class="op">.</span><span class="nam">config</span><span class="op">[</span><span class="str">'FLASKY_COMMENTS_PER_PAGE'</span><span class="op">]</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t188" class="pln"><span class="n"><a href="#t188">188</a></span><span class="t">        <span class="nam">error_out</span><span class="op">=</span><span class="key">False</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t189" class="mis show_mis"><span class="n"><a href="#t189">189</a></span><span class="t">    <span class="nam">comments</span> <span class="op">=</span> <span class="nam">pagination</span><span class="op">.</span><span class="nam">items</span>&nbsp;</span><span class="r"></span></p>
    <p id="t190" class="mis show_mis"><span class="n"><a href="#t190">190</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'post.html'</span><span class="op">,</span> <span class="nam">posts</span><span class="op">=</span><span class="op">[</span><span class="nam">post</span><span class="op">]</span><span class="op">,</span> <span class="nam">form</span><span class="op">=</span><span class="nam">form</span><span class="op">,</span>&nbsp;</span><span class="r"></span></p>
    <p id="t191" class="pln"><span class="n"><a href="#t191">191</a></span><span class="t">                           <span class="nam">comments</span><span class="op">=</span><span class="nam">comments</span><span class="op">,</span> <span class="nam">pagination</span><span class="op">=</span><span class="nam">pagination</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t192" class="pln"><span class="n"><a href="#t192">192</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t193" class="pln"><span class="n"><a href="#t193">193</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t194" class="run"><span class="n"><a href="#t194">194</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/'</span><span class="op">,</span> <span class="nam">methods</span><span class="op">=</span><span class="op">[</span><span class="str">'GET'</span><span class="op">,</span> <span class="str">'POST'</span><span class="op">]</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t195" class="run"><span class="n"><a href="#t195">195</a></span><span class="t"><span class="key">def</span> <span class="nam">index</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t196" class="mis show_mis"><span class="n"><a href="#t196">196</a></span><span class="t">    <span class="nam">form</span> <span class="op">=</span> <span class="nam">PostForm</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t197" class="mis show_mis"><span class="n"><a href="#t197">197</a></span><span class="t">    <span class="key">if</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">can</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">WRITE_ARTICLES</span><span class="op">)</span> <span class="key">and</span> <span class="nam">form</span><span class="op">.</span><span class="nam">validate_on_submit</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t198" class="mis show_mis"><span class="n"><a href="#t198">198</a></span><span class="t">        <span class="nam">post</span> <span class="op">=</span> <span class="nam">Post</span><span class="op">(</span><span class="nam">body</span><span class="op">=</span><span class="nam">form</span><span class="op">.</span><span class="nam">body</span><span class="op">.</span><span class="nam">data</span><span class="op">,</span> <span class="nam">author</span><span class="op">=</span><span class="nam">current_user</span><span class="op">.</span><span class="nam">_get_current_object</span><span class="op">(</span><span class="op">)</span><span class="op">)</span>  <span class="com"># &#30495;&#27491;&#30340;&#29992;&#25143;&#23545;&#35937;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t199" class="mis show_mis"><span class="n"><a href="#t199">199</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">post</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t200" class="mis show_mis"><span class="n"><a href="#t200">200</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.index'</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t201" class="mis show_mis"><span class="n"><a href="#t201">201</a></span><span class="t">    <span class="nam">page</span> <span class="op">=</span> <span class="nam">request</span><span class="op">.</span><span class="nam">args</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'page'</span><span class="op">,</span> <span class="num">1</span><span class="op">,</span> <span class="nam">type</span><span class="op">=</span><span class="nam">int</span><span class="op">)</span>                                        <span class="com"># &#28210;&#26579;&#30340;&#39029;&#25968;&#65292;&#40664;&#35748;&#28210;&#26579;&#31532;&#19968;&#39029;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t202" class="mis show_mis"><span class="n"><a href="#t202">202</a></span><span class="t">    <span class="nam">show_followed</span> <span class="op">=</span> <span class="key">False</span>&nbsp;</span><span class="r"></span></p>
    <p id="t203" class="mis show_mis"><span class="n"><a href="#t203">203</a></span><span class="t">    <span class="key">if</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">is_authenticated</span><span class="op">:</span>  <span class="com"># show_followed&#23384;&#22312;cookies&#20013;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t204" class="mis show_mis"><span class="n"><a href="#t204">204</a></span><span class="t">        <span class="nam">show_followed</span> <span class="op">=</span> <span class="nam">bool</span><span class="op">(</span><span class="nam">request</span><span class="op">.</span><span class="nam">cookies</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="str">'show_followed'</span><span class="op">,</span> <span class="str">''</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t205" class="mis show_mis"><span class="n"><a href="#t205">205</a></span><span class="t">    <span class="key">if</span> <span class="nam">show_followed</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t206" class="mis show_mis"><span class="n"><a href="#t206">206</a></span><span class="t">        <span class="nam">query</span> <span class="op">=</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">followed_posts</span>  <span class="com"># &#26159;&#26174;&#31034;&#20851;&#27880;&#30340;&#29992;&#25143;&#30340;&#25991;&#31456;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t207" class="pln"><span class="n"><a href="#t207">207</a></span><span class="t">    <span class="key">else</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t208" class="mis show_mis"><span class="n"><a href="#t208">208</a></span><span class="t">        <span class="nam">query</span> <span class="op">=</span> <span class="nam">Post</span><span class="op">.</span><span class="nam">query</span>                   <span class="com"># &#26174;&#31034;&#25152;&#26377;&#25991;&#31456;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t209" class="mis show_mis"><span class="n"><a href="#t209">209</a></span><span class="t">    <span class="nam">pagination</span> <span class="op">=</span> <span class="nam">query</span><span class="op">.</span><span class="nam">order_by</span><span class="op">(</span><span class="nam">Post</span><span class="op">.</span><span class="nam">timestamp</span><span class="op">.</span><span class="nam">desc</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><span class="op">.</span><span class="nam">paginate</span><span class="op">(</span>                   <span class="com"># &#21442;&#25968;page&#65292;&#39029;&#25968;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t210" class="pln"><span class="n"><a href="#t210">210</a></span><span class="t">        <span class="nam">page</span><span class="op">,</span> <span class="nam">per_page</span><span class="op">=</span><span class="nam">current_app</span><span class="op">.</span><span class="nam">config</span><span class="op">[</span><span class="str">'FLASKY_POSTS_PER_PAGE'</span><span class="op">]</span><span class="op">,</span> <span class="nam">error_out</span><span class="op">=</span><span class="key">False</span>     <span class="com"># &#21487;&#36873;&#21442;&#25968;per_page&#27599;&#39029;&#30340;&#35760;&#24405;&#25968;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t211" class="pln"><span class="n"><a href="#t211">211</a></span><span class="t">    <span class="op">)</span>                                                                                   <span class="com"># &#21487;&#36873;&#21442;&#25968;error_out&#65292;False&#65292;&#36229;&#20986;&#33539;&#22260;&#36820;&#22238;&#31354;&#21015;&#34920;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t212" class="mis show_mis"><span class="n"><a href="#t212">212</a></span><span class="t">    <span class="nam">posts</span> <span class="op">=</span> <span class="nam">pagination</span><span class="op">.</span><span class="nam">items</span>&nbsp;</span><span class="r"></span></p>
    <p id="t213" class="mis show_mis"><span class="n"><a href="#t213">213</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'index.html'</span><span class="op">,</span> <span class="nam">form</span><span class="op">=</span><span class="nam">form</span><span class="op">,</span> <span class="nam">posts</span><span class="op">=</span><span class="nam">posts</span><span class="op">,</span> <span class="nam">show_followed</span><span class="op">=</span><span class="nam">show_followed</span><span class="op">,</span> <span class="nam">pagination</span><span class="op">=</span><span class="nam">pagination</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t214" class="pln"><span class="n"><a href="#t214">214</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t215" class="pln"><span class="n"><a href="#t215">215</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t216" class="run"><span class="n"><a href="#t216">216</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/admin'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t217" class="run"><span class="n"><a href="#t217">217</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t218" class="run"><span class="n"><a href="#t218">218</a></span><span class="t"><span class="op">@</span><span class="nam">admin_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t219" class="run"><span class="n"><a href="#t219">219</a></span><span class="t"><span class="key">def</span> <span class="nam">for_admins_only</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t220" class="mis show_mis"><span class="n"><a href="#t220">220</a></span><span class="t">    <span class="key">return</span> <span class="str">"&#31649;&#29702;&#21592;&#29992;&#25143;&#30028;&#38754;"</span>&nbsp;</span><span class="r"></span></p>
    <p id="t221" class="pln"><span class="n"><a href="#t221">221</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t222" class="pln"><span class="n"><a href="#t222">222</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t223" class="run"><span class="n"><a href="#t223">223</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/moderator'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t224" class="run"><span class="n"><a href="#t224">224</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t225" class="run"><span class="n"><a href="#t225">225</a></span><span class="t"><span class="op">@</span><span class="nam">permission_required</span><span class="op">(</span><span class="nam">Permission</span><span class="op">.</span><span class="nam">MODERATE_COMMENTS</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t226" class="run"><span class="n"><a href="#t226">226</a></span><span class="t"><span class="key">def</span> <span class="nam">for_moderator_only</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t227" class="mis show_mis"><span class="n"><a href="#t227">227</a></span><span class="t">    <span class="key">return</span> <span class="str">"&#25805;&#20316;&#21592;&#29992;&#25143;&#30028;&#38754;"</span>&nbsp;</span><span class="r"></span></p>
    <p id="t228" class="pln"><span class="n"><a href="#t228">228</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t229" class="pln"><span class="n"><a href="#t229">229</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t230" class="run"><span class="n"><a href="#t230">230</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/user/&lt;username>'</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t231" class="run"><span class="n"><a href="#t231">231</a></span><span class="t"><span class="key">def</span> <span class="nam">user</span><span class="op">(</span><span class="nam">username</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t232" class="mis show_mis"><span class="n"><a href="#t232">232</a></span><span class="t">    <span class="nam">user</span> <span class="op">=</span> <span class="nam">User</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">filter_by</span><span class="op">(</span><span class="nam">username</span><span class="op">=</span><span class="nam">username</span><span class="op">)</span><span class="op">.</span><span class="nam">first</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t233" class="mis show_mis"><span class="n"><a href="#t233">233</a></span><span class="t">    <span class="key">if</span> <span class="nam">user</span> <span class="key">is</span> <span class="key">None</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t234" class="mis show_mis"><span class="n"><a href="#t234">234</a></span><span class="t">        <span class="nam">abort</span><span class="op">(</span><span class="num">404</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t235" class="mis show_mis"><span class="n"><a href="#t235">235</a></span><span class="t">    <span class="nam">posts</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">posts</span><span class="op">.</span><span class="nam">order_by</span><span class="op">(</span><span class="nam">Post</span><span class="op">.</span><span class="nam">timestamp</span><span class="op">.</span><span class="nam">desc</span><span class="op">(</span><span class="op">)</span><span class="op">)</span><span class="op">.</span><span class="nam">all</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t236" class="mis show_mis"><span class="n"><a href="#t236">236</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'user.html'</span><span class="op">,</span> <span class="nam">user</span><span class="op">=</span><span class="nam">user</span><span class="op">,</span> <span class="nam">posts</span><span class="op">=</span><span class="nam">posts</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t237" class="pln"><span class="n"><a href="#t237">237</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t238" class="pln"><span class="n"><a href="#t238">238</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t239" class="run"><span class="n"><a href="#t239">239</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/edit-profile'</span><span class="op">,</span> <span class="nam">methods</span><span class="op">=</span><span class="op">[</span><span class="str">'GET'</span><span class="op">,</span> <span class="str">'POST'</span><span class="op">]</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t240" class="run"><span class="n"><a href="#t240">240</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t241" class="run"><span class="n"><a href="#t241">241</a></span><span class="t"><span class="key">def</span> <span class="nam">edit_profile</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t242" class="mis show_mis"><span class="n"><a href="#t242">242</a></span><span class="t">    <span class="nam">form</span> <span class="op">=</span> <span class="nam">EditProfileForm</span><span class="op">(</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t243" class="mis show_mis"><span class="n"><a href="#t243">243</a></span><span class="t">    <span class="key">if</span> <span class="nam">form</span><span class="op">.</span><span class="nam">validate_on_submit</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t244" class="mis show_mis"><span class="n"><a href="#t244">244</a></span><span class="t">        <span class="nam">current_user</span><span class="op">.</span><span class="nam">name</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">name</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t245" class="mis show_mis"><span class="n"><a href="#t245">245</a></span><span class="t">        <span class="nam">current_user</span><span class="op">.</span><span class="nam">location</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">location</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t246" class="mis show_mis"><span class="n"><a href="#t246">246</a></span><span class="t">        <span class="nam">current_user</span><span class="op">.</span><span class="nam">about_me</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">about_me</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t247" class="mis show_mis"><span class="n"><a href="#t247">247</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">current_user</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t248" class="mis show_mis"><span class="n"><a href="#t248">248</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#36164;&#26009;&#24050;&#26356;&#26032;&#65281;"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t249" class="mis show_mis"><span class="n"><a href="#t249">249</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.user'</span><span class="op">,</span> <span class="nam">username</span><span class="op">=</span><span class="nam">current_user</span><span class="op">.</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t250" class="mis show_mis"><span class="n"><a href="#t250">250</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">name</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">name</span>          <span class="com"># &#26174;&#31034;&#34920;&#21333;&#20043;&#21069;&#65292;&#20026;&#25152;&#26377;&#23383;&#27573;&#35774;&#23450;&#21021;&#22987;&#20540;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t251" class="mis show_mis"><span class="n"><a href="#t251">251</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">location</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">location</span>&nbsp;</span><span class="r"></span></p>
    <p id="t252" class="mis show_mis"><span class="n"><a href="#t252">252</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">about_me</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">current_user</span><span class="op">.</span><span class="nam">about_me</span>&nbsp;</span><span class="r"></span></p>
    <p id="t253" class="mis show_mis"><span class="n"><a href="#t253">253</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'edit_profile.html'</span><span class="op">,</span> <span class="nam">form</span><span class="op">=</span><span class="nam">form</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t254" class="pln"><span class="n"><a href="#t254">254</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t255" class="pln"><span class="n"><a href="#t255">255</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
    <p id="t256" class="run"><span class="n"><a href="#t256">256</a></span><span class="t"><span class="op">@</span><span class="nam">main</span><span class="op">.</span><span class="nam">route</span><span class="op">(</span><span class="str">'/edit-profile/&lt;int:id>'</span><span class="op">,</span> <span class="nam">methods</span><span class="op">=</span><span class="op">[</span><span class="str">'GET'</span><span class="op">,</span> <span class="str">'POST'</span><span class="op">]</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t257" class="run"><span class="n"><a href="#t257">257</a></span><span class="t"><span class="op">@</span><span class="nam">login_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t258" class="run"><span class="n"><a href="#t258">258</a></span><span class="t"><span class="op">@</span><span class="nam">admin_required</span>&nbsp;</span><span class="r"></span></p>
    <p id="t259" class="run"><span class="n"><a href="#t259">259</a></span><span class="t"><span class="key">def</span> <span class="nam">edit_profile_admin</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t260" class="mis show_mis"><span class="n"><a href="#t260">260</a></span><span class="t">    <span class="nam">user</span> <span class="op">=</span> <span class="nam">User</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">get_or_404</span><span class="op">(</span><span class="nam">id</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t261" class="mis show_mis"><span class="n"><a href="#t261">261</a></span><span class="t">    <span class="nam">form</span> <span class="op">=</span> <span class="nam">EditProfileAdminForm</span><span class="op">(</span><span class="nam">user</span><span class="op">=</span><span class="nam">user</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t262" class="mis show_mis"><span class="n"><a href="#t262">262</a></span><span class="t">    <span class="key">if</span> <span class="nam">form</span><span class="op">.</span><span class="nam">validate_on_submit</span><span class="op">(</span><span class="op">)</span><span class="op">:</span>&nbsp;</span><span class="r"></span></p>
    <p id="t263" class="mis show_mis"><span class="n"><a href="#t263">263</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">email</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">email</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t264" class="mis show_mis"><span class="n"><a href="#t264">264</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">username</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">username</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t265" class="mis show_mis"><span class="n"><a href="#t265">265</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">confirmed</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">confirmed</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t266" class="mis show_mis"><span class="n"><a href="#t266">266</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">role</span> <span class="op">=</span> <span class="nam">Role</span><span class="op">.</span><span class="nam">query</span><span class="op">.</span><span class="nam">get</span><span class="op">(</span><span class="nam">form</span><span class="op">.</span><span class="nam">role</span><span class="op">.</span><span class="nam">data</span><span class="op">)</span>  <span class="com"># form.role.data&#26159;&#25972;&#25968;&#65292;user.role&#26159;&#35282;&#33394;id&#23545;&#24212;&#30340;&#35282;&#33394;&#21517;&#31216;</span>&nbsp;</span><span class="r"></span></p>
    <p id="t267" class="mis show_mis"><span class="n"><a href="#t267">267</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">name</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">name</span><span class="op">.</span><span class="nam">name</span>&nbsp;</span><span class="r"></span></p>
    <p id="t268" class="mis show_mis"><span class="n"><a href="#t268">268</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">location</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">location</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t269" class="mis show_mis"><span class="n"><a href="#t269">269</a></span><span class="t">        <span class="nam">user</span><span class="op">.</span><span class="nam">about_me</span> <span class="op">=</span> <span class="nam">form</span><span class="op">.</span><span class="nam">about_me</span><span class="op">.</span><span class="nam">data</span>&nbsp;</span><span class="r"></span></p>
    <p id="t270" class="mis show_mis"><span class="n"><a href="#t270">270</a></span><span class="t">        <span class="nam">db</span><span class="op">.</span><span class="nam">session</span><span class="op">.</span><span class="nam">add</span><span class="op">(</span><span class="nam">user</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t271" class="mis show_mis"><span class="n"><a href="#t271">271</a></span><span class="t">        <span class="nam">flash</span><span class="op">(</span><span class="str">"&#20010;&#20154;&#20449;&#24687;&#24050;&#20462;&#25913;&#65281;"</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t272" class="mis show_mis"><span class="n"><a href="#t272">272</a></span><span class="t">        <span class="key">return</span> <span class="nam">redirect</span><span class="op">(</span><span class="nam">url_for</span><span class="op">(</span><span class="str">'.user'</span><span class="op">,</span> <span class="nam">username</span><span class="op">=</span><span class="nam">user</span><span class="op">.</span><span class="nam">username</span><span class="op">)</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t273" class="mis show_mis"><span class="n"><a href="#t273">273</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">email</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">email</span>&nbsp;</span><span class="r"></span></p>
    <p id="t274" class="mis show_mis"><span class="n"><a href="#t274">274</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">username</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">username</span>&nbsp;</span><span class="r"></span></p>
    <p id="t275" class="mis show_mis"><span class="n"><a href="#t275">275</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">confirmed</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">confirmed</span>&nbsp;</span><span class="r"></span></p>
    <p id="t276" class="mis show_mis"><span class="n"><a href="#t276">276</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">role</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">role</span>&nbsp;</span><span class="r"></span></p>
    <p id="t277" class="mis show_mis"><span class="n"><a href="#t277">277</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">name</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">name</span>&nbsp;</span><span class="r"></span></p>
    <p id="t278" class="mis show_mis"><span class="n"><a href="#t278">278</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">location</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">location</span>&nbsp;</span><span class="r"></span></p>
    <p id="t279" class="mis show_mis"><span class="n"><a href="#t279">279</a></span><span class="t">    <span class="nam">form</span><span class="op">.</span><span class="nam">about_me</span><span class="op">.</span><span class="nam">data</span> <span class="op">=</span> <span class="nam">user</span><span class="op">.</span><span class="nam">about_me</span>&nbsp;</span><span class="r"></span></p>
    <p id="t280" class="mis show_mis"><span class="n"><a href="#t280">280</a></span><span class="t">    <span class="key">return</span> <span class="nam">render_template</span><span class="op">(</span><span class="str">'edit_profile.html'</span><span class="op">,</span> <span class="nam">form</span><span class="op">=</span><span class="nam">form</span><span class="op">,</span> <span class="nam">user</span><span class="op">=</span><span class="nam">user</span><span class="op">)</span>&nbsp;</span><span class="r"></span></p>
    <p id="t281" class="pln"><span class="n"><a href="#t281">281</a></span><span class="t">&nbsp;</span><span class="r"></span></p>
</div>
<div id="footer">
    <div class="content">
        <p>
            <a class="nav" href="index.html">&#xab; index</a> &nbsp; &nbsp; <a class="nav" href="https://coverage.readthedocs.io">coverage.py v5.5</a>,
            created at 2021-04-16 21:12 +0800
        </p>
    </div>
</div>
</body>
</html>
